<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<html>
  <head>
	<meta charset="utf-8">
    <title>pie chart</title>
	<script src="../js/d3.v3.min.js"></script>

  <link rel="stylesheet" href="../pie/css/d3.pie.css" type="text/css"></link>
 
<style>
#chartPanel {
	float: left; 
}
#controlPanel { 
	position: absolute;
	right: 10px;
	top: 10px;
	width: 260px;
}
.legend {
	font-size: 20px;
} 
</style>
  <s:head/>
  </head>

  <body>
  
  <div id="chartPanel"></div>
  <div id="controlPanel">
  	
  	<form action="<s:url action="fileUpload" namespace="/pie"/>" method="post" enctype="multipart/form-data">
  		<input type="hidden" name="destPage" value="<%= request.getServletPath()%>" />
  		<div>
  			<label for="dataFile">data file</label>
  			<s:file name="data" />
  		</div>
  		<div>
  			<input type="submit"/>
  		</div>
  	</form>
  </div>
  
<script>

var width = 960,
	height = 500,
	radius = Math.min(width, height) / 2;

var color = d3.scale.ordinal()
				.range(["#98abc5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56", "#d0743c", "#ff8c00"]);

var arc = d3.svg.arc()
			.outerRadius(radius - 10)
			.innerRadius(0);

var pie = d3.layout.pie()
			.sort(null)
			.value(function (d) { return d.population; });

var svg = d3.select("#chartPanel").append("svg")
			.attr("width", width)
			.attr("height", height)
			.append("g")
			.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");

d3.csv('<s:property value="#session['CURRENT_FILE']"/>', function (error, data) {
	
	data.forEach(function (d) {
		d.population = +d.population;
	});
	
	var g = svg.selectAll(".arc")
				.data(pie(data))
				.enter().append("g")
				.attr("class", "arc");
	
	g.append("path")
		.attr("d", arc)
		.style("fill", function (d) { return color(d.data.age); });
	
	g.append("text")
		.attr("transform", function (d) { return "translate(" + arc.centroid(d) + ")"; })
		.attr("dy", ".35em")
		.style("text-anchor", "middle")
		.text(function (d) { return d.data.age; });
	
}); // end d3.csv

</script>
  
  
  </body>
</html>



















